//
// Created by Jisam on 2024/5/27.
//
#include <iostream>
#include <vector>

using namespace std;

// 构建next数组
vector<int> getNext(const string& pattern) {
    int n = pattern.size();
    vector<int> next(n, 0);

    int i = 1, j = 0;
    while (i < n) {
        if (pattern[i] == pattern[j]) {
            next[i] = j + 1;
            i++;
            j++;
        } else {
            if (j > 0) {
                j = next[j - 1];
            } else {
                next[i] = 0;
                i++;
            }
        }
    }
    return next;
}

// KMP算法匹配字符串
void kmp(const string& text, const string& pattern) {
    int m = text.size();
    int n = pattern.size();
    vector<int> next = getNext(pattern);

    int i = 0, j = 0;
    while (i < m) {
        if (text[i] == pattern[j]) {
            if (j == n - 1) {
                // 匹配成功，返回起始位置
                cout<< i - j +1 <<endl;
            }
            i++;
            j++;
        } else {
            if (j > 0) {
                j = next[j - 1];
            } else {
                i++;
            }
        }
    }

    for(int i=0;i<pattern.size();i++) cout<<next[i]<<" ";
}

int main() {
    string text, pattern;
    cin >> text >> pattern;
    kmp(text, pattern);

    return 0;
}